﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraGrid.Views.Grid;
using COMOSOFT.Class;

namespace COMOSOFT.OrderBusiness.Forms
{
    public partial class FrmAddOrderFactory : Form
    {
        ClassShare cls = new ClassShare("FrmAddOrderFactory");
        FrmFactoryPurchaseMaster frFPM = null;
        string OIDS = null;
        public FrmAddOrderFactory(FrmFactoryPurchaseMaster newFPM)
        {
            InitializeComponent();
            this.frFPM = newFPM;
        }
        private void FrmAddOrderFactory_Load(object sender, EventArgs e)
        {            
            this.sp_SelectOrderFactoryTableAdapter.Fill(this.dataSetOrderManagement.sp_SelectOrderFactory);
        }

        #region[Select Order]
        private void dataNavigator_AddOrder_ButtonClick(object sender, DevExpress.XtraEditors.NavigatorButtonClickEventArgs e)
        {
            switch (e.Button.Tag.ToString())
            {
                case "Add":
                    try
                    {
                        if (gridView_SelectPO.FocusedRowHandle >= 0)
                        {
                            int[] numrow = gridView_SelectPO.GetSelectedRows();
                            foreach (int i in numrow)
                            {
                                DataRow row = gridView_SelectPO.GetDataRow(i);
                                if (i == 0)
                                    OIDS = row["OID"].ToString();
                                else
                                    OIDS += "," + row["OID"].ToString();
                            }
                            cls.UpdateData("sp_FtyPurDetailsInsert", new string[2] { "@OIDs", "@FBID" }, new object[2] { OIDS, ClassShare.fpid });
                            frFPM.LoadFPM();
                        }
                        this.Close();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                    break;
                case "Refresh":
                    sp_SelectOrderFactoryTableAdapter.Fill(dataSetOrderManagement.sp_SelectOrderFactory);
                    break;
                case "Exit":
                    this.Close();
                    break;
                default :
                    break;
            }
        }
        #endregion
    }
}
